/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: MenuInfo
 * @Package com.rx.uua.dto
 * @Description: 菜单信息
 * @author: 陈锦韬
 * @date: 2021\8\1 0001
 * @version V1.0
 * @Copyright: 2021 陈锦韬  All rights reserved.
 */
package com.rx.uua.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.rx.core.iface.TreeNode;
import com.rx.core.util.EmptyChecker;
import com.rx.core.util.RxUtil;
import com.rx.uua.vo.UuaMenuInfo;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Administrator
 * @Description: 菜单信息
 * @date: 2021\8\1 0001
 */
@Data
public class MenuInfo implements TreeNode {
    private String bid;
    /**
     * 根编码
     */
    private String rootCode;
    /**
     * 父代码
     */
    private String parentCode;

    /**
     * 菜单编码
     */
    private String menuCode;

    /**
     * 名称
     */
    private String name;

    /**
     * 路由路径
     */
    private String path;

    /**
     * 默认指向
     */
    private String redirect;

    /**
     * 组件
     */
    private String component;


    protected List<TreeNode> children;

    /**
     * 元数据
     */
    private Meta meta;

    /**
     *
     */
    @Data
    public static class Meta{
        /**
         * 展示
         */
        String title;
        /**
         * 图标
         */
        String icon;
        /**
         * 打开页面是否是前一个
         */
        String affix;
    }


    @Override
    public String parentCode() {
        return parentCode;
    }

    @Override
    public String rootCode() {
        return rootCode;
    }

    @Override
    public String code() {
        return menuCode;
    }

    @Override
    public List childList() {
        if(EmptyChecker.isEmpty(children)){
            children = new ArrayList<>();
        }
        return children;
    }

    public static MenuInfo create(UuaMenuInfo uuaMenuInfo){
        MenuInfo menuInfo = new MenuInfo();
        RxUtil.copyProperties(uuaMenuInfo,menuInfo);
        menuInfo.setName(uuaMenuInfo.getMenuName());
        MenuInfo.Meta meta = new Meta();

        if (EmptyChecker.isEmpty(uuaMenuInfo.getLocal())){
            meta.setTitle(uuaMenuInfo.getMenuName());
        }else {
            meta.setTitle(uuaMenuInfo.getLocal());
        }

        meta.setIcon(uuaMenuInfo.getIcon());
        menuInfo.setMeta(meta);
        menuInfo.setPath(uuaMenuInfo.getRoute());

        return menuInfo;
    }
}
